#-*-coding:utf-8-*-
import time

import requests
from lxml import etree
import xlwt

def getCity():
    url='https://www.aqistudy.cn/historydata/'
    headers={
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'
    }
    html=requests.get(url=url,headers=headers).content.decode('utf-8')
    tree=etree.HTML(html)
    li_list=tree.xpath('//div[@class="bottom"]//ul[@class="unstyled"]//li')

    workbook = xlwt.Workbook(encoding='utf-8')
    worksheet = workbook.add_sheet('city')
    worksheet.write(0,0,"城市名")
    worksheet.write(0,1,"经纬度")
    id=0
    for li in li_list:
        city_name=li.xpath('./a/text()')[0]
        id=id+1
        worksheet.write(id,0,city_name)
    workbook.save("city.xls")
    print("城市名已生成")
